﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

namespace DNA.Mvc.Publishing
{
    [Table("publishing_categories")]
    public class Category
    {
        [Key]
        public virtual int ID { get; set; }
        
        /// <summary>
        /// Gets/Sets the category title.
        /// </summary>
        [MaxLength(50)]
        public virtual string Title { get; set; }

        /// <summary>
        /// Gets/Sets the category description.
        /// </summary>
        [Column(TypeName="ntext")]
        public virtual string Description { get; set; }
        
        [Required]
        public virtual bool AllowAnonymousPostComment { get; set; }

        public virtual int? ArticleType { get; set; }

        [Required]
        public virtual bool EnableVersioning { get; set; }
        
        [Required]
        public virtual bool IsModerated { get; set; }

        public virtual DateTime LastPosted { get; set; }

        public virtual int ParentID { get; set; }
        
        [MaxLength(1024)]
        public virtual string Path { get; set; }

        [Required]
        public virtual int Pos { get; set; }

        [Required]
        public virtual int TotalPosts { get; set; }

        [MaxLength(1024)]
        public virtual string ImageUrl { get; set; }

        [MaxLength(1024)]
        public virtual string Url { get; set; }

        [NotMapped]
        public virtual bool IsRoot 
        {
            get 
            {
                return ParentID == 0;
            } 
        }

        public virtual ICollection<Article> Articles { get; set; }

        public virtual string GetRootPath()
        {
            if (!string.IsNullOrEmpty(Path))
                return Path.Split('/')[0];
            return "";
        }

    }
}
